package 剑指offer;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class _45把数组排成最小的数 {
    public String minNumber(int[] nums) {
        if(nums.length == 0){
            return "";
        }
        List<Integer> list = new ArrayList<Integer>();
        for (int n : nums){
            list.add(n);
        }
        Collections.sort(list, new Comparator<Integer>() {
            @Override
            public int compare(Integer x, Integer y) {
                String xs = x + "" + y;
                String ys = y + "" + x;
                return xs.compareTo(ys);
            }
        });
        String result = new String();
        for (Integer e : list){
            result += e;
        }
        return result;
    }
}
